/**
 * Created by liguangsong on 16/8/12.
 */
import React, { PropTypes } from 'react'
import '../../css/container/content.css'
import ContentText from './contentText.js'
import { connect } from 'react-redux'

var Content = React.createClass({
    getInitialState() {

        return {
            textData: []
        };
    },

    componentWillMount() {
        this.getPageData();
    },

    getPageData() {
        $.ajax({
            url: '../../../content_text.json',
            dataType: 'json',
            success: function(result) {
                this.setState( {
                    textData: result["content_text"][this.props.page - 1]
                });
            }.bind(this)
        });
    },

    getContentText() {
        var view = [];
        for (var i = 0; i < this.state.textData.length; i++) {
            var data = this.state.textData[i];
            view.push(
                <ContentText key={i} title={data["title"]} time={data["time"]} type={data["type"]} image={data["image"]} text={data["text"]} />
            );
        }

        return view;
    },

    render() {
        return (
            <div className="content">
                { this.getContentText() }
            </div>
        )
    }
});

function select(state) {
    return {
        page: state.selectPage.page
    }
}

//export default connect(select)(Content);
export default Content;